"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class RandomUtil {
    /** 随机minNum到maxNum的数字 （包含maxNum） */
    static nextInt(minNum, maxNum) {
        return Math.floor(Math.random() * (maxNum - minNum + 1) + minNum);
    }
    static nextNumber(minNum, maxNum) {
        return Math.random() * (maxNum - minNum) + minNum;
    }
    static nextSign() {
        let temp = Math.random();
        if (temp < 0.5) {
            return 1;
        }
        return -1;
    }
    static nextBoolean() {
        let temp = Math.random();
        if (temp < 0.5) {
            return true;
        }
        return false;
    }
    static randomArr(nowArr, needNum) {
        let tempArr = nowArr.concat();
        let resultArr = [];
        for (let index = 0; index < needNum; index++) {
            if (tempArr.length <= 0) {
                break;
            }
            let randomIndex = RandomUtil.nextInt(0, tempArr.length - 1);
            resultArr.push(tempArr.splice(randomIndex, 1)[0]);
        }
        return resultArr;
    }
    static randomItem(nowArr) {
        return this.randomArr(nowArr, 1)[0];
    }
    static randomIndexByPercent(rateList = [100, 100, 100]) {
        let tempList = [];
        let totalTemp = 0;
        for (let i = 0; i < rateList.length; i++) {
            totalTemp += rateList[i];
            tempList[i] = totalTemp;
        }
        let randomTemp = this.nextInt(0, totalTemp);
        let resultIndex = tempList.length - 1;
        for (let i = 0; i < tempList.length; i++) {
            if (randomTemp <= tempList[i]) {
                resultIndex = i;
                break;
            }
        }
        return resultIndex;
    }
}
exports.default = RandomUtil;
